﻿@*帖子列表页面*@
@using EasyCourse.Model;
@{
    Layout = null;
    ViewData["MenuIndex"] = 11;
    CommonPageInfo pageInfo = ViewData[CommonViewDataKey.CommonPageInfo] as CommonPageInfo;
    ViewData["CourseId"] = pageInfo.CourseId;
}

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>讨论区</title>
    @Html.Partial("~/Views/Share/PublicHeader.cshtml")
</head>
<body>
    @Html.Partial("~/Views/Share/PublicTopNav.cshtml")
    <div class="container">
        <div class="row">
            <h1 class="topTitle-h1">
                @pageInfo.CourseName
                <br>
                <small>广州中医药大学康复治疗微课程网络学习平台</small>
            </h1>
        </div>
    </div>
    @Html.Partial("~/Views/Share/PublicNav.cshtml",this.ViewData)
    <div class="container wrap mb15">
        <div class="row">
            <div class="col-xs-9 publicLBox2">
                <div class="lBox part">
                    <div class="lBox-th">
                        <h3>讨论区</h3>
                    </div>
                    <div class="lBox-tb">
                        <form class="form-horizontal " role="form">
                            <div class="form-group ">
                                <div class="col-xs-6">
                                    <input type="text" class="form-control" id="JSearchTit" placeholder="请输入标题">
                                </div>
                                <div class="col-xs-6">
                                    <button type="button" id="JSearchBtn" class="btn btn-success"><span class="glyphicon glyphicon-search"></span> 搜索 </button>
                                </div>
                            </div>
                        </form>
                        <table class="table table-striped table-hover ">
                            <thead>
                                <tr>
                                    <th width="50%">标题</th>
                                    <th width="10%">作者</th>
                                    <th width="10%">发表日期</th>
                                    <th width="10%">点击量</th>
                                    <th width="10%">回复量</th>
                                    <th width="10%">最后回复</th>
                                </tr>
                            </thead>
                            <tbody id="JzyList">
                                
                            </tbody>
                        </table>
                        <div class="row clearfix well d-page">
                            <div id="PagInfo" class="pull-left sum"></div>
                            <div class="clearfix pull-right">
                                <ul id="PageTool" class="pagination"></ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xs-3">
                @Html.Partial("~/Views/Share/PublicRBox.cshtml", ViewData)
                <div class="rBox part rBox-tools mt15">
                    <a class="btn btn-success btn-lg btn-block" href="" id="JaddPostsBtn" target="_blank">发布新帖</a>
                </div>
            </div>
        </div>
    </div>
    @Html.Partial("~/Views/Share/PublicFooter.cshtml")
    @Html.Partial("~/Views/Share/PublicCommonJs.cshtml")
    <script type="text/javascript">
        var JzyList = $("#JzyList");
        var _JlistTop = $(".wrap").offset().top - $(".topNavPar").height(); //点击换页的时候导航回到的高度
        var _courseId = "";
        var _state = false;
        var _title = "";
        var _pageNo = 1;
        var JSearchBtn = $("#JSearchBtn");
        var JSearchTit = $("#JSearchTit");
        $(document).ready(function () {
            _courseId = $.getUrlParam("CourseId");
            //发布新帖链接
        $("#JaddPostsBtn").attr("href", "@Url.Action("DiscussionInfoAdd", "Discussion")?CourseId=" + _courseId);
        function getList(pageNo, title) {
            _title = title;
            _pageNo = pageNo;
            $.easyPost("@Url.Action("SearchDiscussion", "Discussion")", {
                "PageNO": _pageNo,
                "PageSize": 20,
                "CourseId": _courseId,
                "Title": _title
            }, function (data) {
                   if (!data.result) {
                       showTips.open(data.message);
                       return;
                   }
                   if (data.rows.length > 0) {
                       var _row = data.rows,
                           _rowL = _row.length,
                           _html = '';
                       options = {
                           totalPages: data.totalPage,
                           total: data.total,
                           currentPage: _pageNo,
                           numberOfPages: 20,
                           onPageClicked: function (event, originalEvent, type, page) {
                               getList(page, title)
                           }
                       }
                       initialPaginator(options, "PageTool", "PagInfo");
                       for (var i = 0; i < _rowL; i++) {
                           var item = _row[i];
                           var _date = item.CreateTime.toString().replace(/\//g, "");
                           var time = eval('new ' + _date);
                           _html += '<tr>' +
                                       '<td>' +
                                           '<a href="@Url.Action("Detail", "Discussion")?CourseId=' + _courseId + '&DiscussId=' + item.Id + '" target="_blank">' + item.Title + '</a>' +
                                        '</td>' +
                                        '<td>' + item.Creator + '</td>' +
                                        '<td>' + time.format('yyyy-MM-dd') + '</td>' +
                                        '<td>' + item.VisitTimes + '</td>' +
                                        '<td>' + item.ReplyTimes + '</td>' +
                                        '<td>' + item.Replyer + '</td>' +
                                    '</tr>';
                        }
                        JzyList.html(_html);
                        if (_state) {
                            $('html,body').animate({ scrollTop: _JlistTop }, 0);
                        }
                        _state = true;

                   } else {
                       var _html = '<tr><td colspan="6" align="center">暂无内容</td></tr>'
                       JzyList.html(_html)
                    }
               }, "json");
        }
        getList(_pageNo, _title);
        JSearchBtn.bind("click", function () {
            _title = JSearchTit.val();
            _pageNo = 1;
            getList(_pageNo, _title);
        })
        });


    </script>
</body>
</html>